﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;


namespace Wayloop.Blog.Core.Data.Entities
{
    public class Post : AbstractEntity
    {
        protected IList<Comment> comments;


        /// <summary>
        /// Gets or sets the slug.
        /// </summary>
        /// <value>The slug.</value>
        [Required]
        public virtual string Slug { get; set; }


        /// <summary>
        /// Gets or sets the title.
        /// </summary>
        /// <value>The title.</value>
        [Required]
        public virtual string Title { get; set; }


        /// <summary>
        /// Gets or sets the summary.
        /// </summary>
        /// <value>The summary.</value>
        public virtual string Summary { get; set; }


        /// <summary>
        /// Gets or sets the body.
        /// </summary>
        /// <value>The body.</value>
        [Required]
        public virtual string Body { get; set; }


        /// <summary>
        /// Gets or sets the "created on" timestamp.
        /// </summary>
        /// <value>The "created on" timestamp.</value>
        public virtual DateTime CreatedOn { get; set; }


        /// <summary>
        /// Gets or sets the "modified on" timestamp.
        /// </summary>
        /// <value>The "modified on" timestamp.</value>
        public virtual DateTime ModifiedOn { get; set; }


        /// <summary>
        /// Gets or sets the "published on" timestamp.
        /// </summary>
        /// <value>The "published on" timestamp.</value>
        public virtual DateTime? PublishedOn { get; set; }


        /// <summary>
        /// Gets or sets the comments.
        /// </summary>
        /// <value>The comments.</value>
        public virtual IList<Comment> Comments
        {
            get { return comments; }
            set { comments = value; }
        }


        /// <summary>
        /// Initializes a new instance of the <see cref="Post"/> class.
        /// </summary>
        public Post()
        {
            comments = new List<Comment>();
        }


        /// <summary>
        /// Adds the specified comment to this instance.
        /// </summary>
        /// <param name="comment">The comment.</param>
        public virtual void AddComment(Comment comment)
        {
            comment.Post = this;
            Comments.Add(comment);
        }


        /// <summary>
        /// Gets the model signature.
        /// </summary>
        /// <returns>
        /// An array of property values that make up the "signature" of the model.
        /// </returns>
        protected override object[] GetEntitySignature()
        {
            return new object[] {
                Slug,
                Title,
                Summary,
                Body,
                CreatedOn,
                ModifiedOn,
                PublishedOn
            };
        }
    }
}